1. /* simcv2bn.cpp by K.Tsuru */
  2. // function ID = 402 BRADIX
  3. /****************************************************
  4. SInteger class
  5. It provides the radix conversion SLong to SInteger.
  6. *****************************************************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. SInteger SInteger::NConvToBin(const SLong& m){
  11. SInteger result;
  12. uint szD = m.Head()+1u;
  13. if(szD <= 2){ //m has two or under figures. including the case m=0.
  14. long v = (long)m[1]*DRADIX + (long)m[0];
  15. if(m.Sign() < 0) v = -v;
  16. result.SetLong(v);
  17. return result;
  18. }
  19. // m != 0
  20. uint szB = uint( szD*( log10((double)DRADIX)/log10((double)BRADIX) ) )+ 1u; // ver. 2.17
  21. result.FigureAlloc(szB, 0);
  22. int h = m.Head(), j = (int)h - 1;
  23. const fType* mv = m.ReadFigures();
  24. result.SetLong((long)mv[h]); //It sets the top figure. result > 0
  25. while(j >= 0){
  26. IsMult(result, DRADIX, result); //result*=DRADIX;
  27. //It is faster than IIAdd() by a ratio 1.4.
  28. IsAdd(result, mv[j], result); //result+=mv[j];
  29. j--;
  30. }
  31. result.SetSign(m.Sign());
  32. result.CutDown(result.POP);
  33. if( 2u*(result.aHead+1) <= result.figure.size() ) result.DoCutDown();
  34. return result;
  35. }
  36. SInteger SInteger::ConvToBin(const SLong& m){
  37. if(m.Type() == m.BIN_INT){
  38. SInteger r;
  39. r.CopyValue(m, r.COPY); return r;
  40. }
  41. // Head()+1 =< iNconvBinMaxFig : BSConvToBin() is faster than NConvTodec()
  42. SInteger result;
  43. if(m.Head()+1 <= iNconvBinMaxFig) result = NConvToBin(m);
  44. else result = BSConvToBin(m); // ver.2.17
  45. return result;
  46. }

simcv2bn.cpp : last modifiled at 2017/03/13 14:31:59(1,527 bytes)
created at 2016/04/25 14:53:17
The creation time of this html file is 2017/10/25 11:09:45 (Wed Oct 25 11:09:45 2017).